var basePath = $("#basePath").val();
$(document).ready(function (){
        menuCss("新闻");
    queryNewsInfo();
});


function queryNewsInfo() {
        var newsId = $("#newsId").val();
        var url = basePath+"/news/queryNewsInfo";
        publicAjax(url,"POST",{newsId:newsId},function (data){
                if(data.ret == 200){
                    bindNewsData(data.data);

                }else{
                    flavrShowByTime(data.msg,null,"danger",false);
                }
        });
}


function bindNewsData(obj){
        var statusStr =  "";
        if(obj.status == 0){
            statusStr = "草稿";
        }else if(obj.status == 1){
            statusStr = "已发布";
        }else if(obj.status == 2){
            statusStr = "已撤回";
        }

        $("#titleSpan").html(obj.title == null ? '' : obj.title);
        $("#newsTypeNameSpan").html(obj.newsTypeName == null ? '' : obj.newsTypeName);
        $("#publisTimeSpan").html(obj.publisTime == null ? '' : obj.publisTime);
        $("#publishPersonNameSpan").html(obj.publishPersonName == null ? '' : obj.publishPersonName);
        $("#statusSpan").html(statusStr);
        $("#remarkSpan").html(obj.remark == null ? '' : obj.remark);
        $("#publishContentSpan").html(obj.publishContent == null ? '' : obj.publishContent);

        var html = "";
        if(obj.fileViewList == null || obj.fileViewList.length == 0){
            html = "<tr><td class='text-center text-muted' colspan='7'>暂无文件</td></tr>";
        }else{
            $.each(obj.fileViewList,function (index,item){
                html+="<tr><td class='text-center text-muted' >"+(index+1)+"</td>" +
                    "<td class='text-center text-muted' >"+(item.fileTypeName==null?'':item.fileTypeName)+"</td>" +
                    "<td class='text-muted text-center'><a href='javascript:showFile(\""+item.fileUrl+"\",\""+item.fileName+"\")'>"+(item.fileName == null?'':item.fileName)+"</a></td>" +
                    "<td class='text-center text-muted' >"+(item.startDate == null ? '' : item.startDate)+"</td>" +
                    "<td class='text-center text-muted' >"+(item.endDate == null ? '' : item.endDate )+"</td>" +
                    "<td class='text-center text-muted' >"+(item.fileSize == null ? 0 : item.fileSize)+"Kb</td>" +
                    "<td class='text-muted text-center'><button type='button' class='btn btn-danger btn-xs' title='下载' onclick='fileDownload(\""+item.fileName+"\",\""+item.fileUrl+"\",\""+item.fileSuffix+"\")'><i class='fa fa-fw fa-download'></i></button></td>" +
                    "</tr>";
            });
        }
        $("#news_file_list").html(html);
}

function fileDownload(fileName,filePath,fileSuffix){
    location.href= basePath+"/file/fileDownload?filePath="+filePath+"&fileName="+fileName;
}

function showFile(url,file){
    $("#file_show_modal").iziModal({
        zindex:999999,
        headerColor: '#00c0ef',
        title: '预览',
        subtitle: file,
        overlayClose: true,
        history:false,
        iframe : true,
        iframeURL:url,
        fullscreen: true,
        openFullscreen: false,
        onClosed:function(){
            $('#file_show_modal').iziModal('destroy');
        }
    });
    $("#file_show_modal").iziModal('open');
}
